package gdr.action;

import gdr.dev.Rendable;
import gdr.map.Position;
import gdr.dev.*;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;


/**
 * Azione che gestisce lo spostamento del cursore sul campo di battaglia, 
 * estendere questa classe per particolarizzare le reazioni in base al tasto premuto.
 * @author Giorgio Vitale
 *
 */
public class KeyManager extends Azione{
	
	protected Position p;
	protected SuperGDR9000 gdr;
	
	
	public void init(){
		super.activate();
		getExecuter().setActiveElement(INIZIALIZZA);
	}
	
	
	public KeyManager(){
		super();
		getExecuter().addElement(INIZIALIZZA, new Rendable()
		{	public void update(long elapsedTime){
				int key = gdr.bsInput.getKeyPressed();
				boolean anyKeyPressed = true;
				switch (key)
				{	case KeyEvent.VK_UP:   key_pressed_UP(); 	key_pressed_arrow(); break;
					case KeyEvent.VK_DOWN: key_pressed_DOWN(); 	key_pressed_arrow(); break;
					case KeyEvent.VK_RIGHT:key_pressed_RIGHT(); key_pressed_arrow(); break;
					case KeyEvent.VK_LEFT: key_pressed_LEFT(); 	key_pressed_arrow(); break;
					case KeyEvent.VK_ENTER:key_pressed_ENTER(); break;
					case KeyEvent.VK_END:  key_pressed_EXIT(); break;
					default: anyKeyPressed = false;
				}
				manager.getGame().bsInput.refresh();
				if (anyKeyPressed) key_pressed_anyKeyPressed();
			}
			public void render(Graphics2D g){}
		});
	}

	/** tasto premuto SU*/
	protected void key_pressed_UP(){
		p = manager.getCoordinateCalc().getCenter();
		if (p.getY()>0) p.setY(p.getY()-1); 
	}
	/** tasto premuto SINISTRA*/
	protected void key_pressed_LEFT(){
		p = manager.getCoordinateCalc().getCenter();
		if (p.getX()>0) p.setX(p.getX()-1);
	}
	/** tasto premuto DESTRA*/
	protected void key_pressed_RIGHT(){
		p = manager.getCoordinateCalc().getCenter();
		if (p.getX()<manager.getMap().getWidth()-1) p.setX(p.getX()+1);
	}
	/** tasto premuto GIU'*/
	protected void key_pressed_DOWN(){
		p = manager.getCoordinateCalc().getCenter();
		if (p.getY()<manager.getMap().getHeight()-1) p.setY(p.getY()+1);
	}
	/** tasto premuto ENTER*/
	protected void key_pressed_ENTER(){
		
	}
	/** tasto premuto EXIT*/
	protected void key_pressed_EXIT(){
		
	}
	/** attivato se si preme un tasto freccia*/
	protected void key_pressed_arrow(){
		
	}
	/** attivato se viene premuto un qualunque tasto */
	protected void key_pressed_anyKeyPressed(){
		
	}


	public SuperGDR9000 getGdr() {
		return gdr;
	}
	public void setGdr(SuperGDR9000 gdr) {
		this.gdr = gdr;
	}
	public void setManager(gdr.battle.BattleManagerOld manager){
		gdr = manager.getGame();
		super.setManager(manager);
	}
}